#include "Paradise of the Past.h"

vector<arrow>playerArrows;
void arrow::dertascoreGet(int temp) {
	dertascore = temp;
}
player::player(int temp1, int temp2, int temp3) {
	x = temp1;
	y = temp2;
	speed = temp3;
	HP = 100;
	score = 0;
	loadimage(&playerimg, L"aili(1).png");
}
int player::getWidth() {
	return playerimg.getwidth();
}
int player::getHeight() {
	return playerimg.getheight();
}
void player::playerDraw() {
	putimage(x, y, &playerimg);
}
void player::playerMove() {
	if ((GetAsyncKeyState(VK_LEFT) || GetAsyncKeyState('A')) && x > 0) {
		x -= speed;
	}
	else if ((GetAsyncKeyState(VK_RIGHT) || GetAsyncKeyState('D')) && x < 1080 - playerimg.getwidth()) {
		x += speed;
	}
	else if ((GetAsyncKeyState(VK_UP) || GetAsyncKeyState('W')) && y > 0) {
		y -= speed;
	}
	else if ((GetAsyncKeyState(VK_DOWN) || GetAsyncKeyState('S')) && y < 810 - playerimg.getheight()) {
		y += speed;
	}
}
void player::archery() {
	static int frequency = 0;
	frequency++;
	if (frequency % 5 == 1) {
		if (GetAsyncKeyState(VK_SPACE)) {
			arrow temparrow;
			temparrow.x = x;
			temparrow.y = y - playerimg.getheight();
			temparrow.speed = 2 * speed;
			loadimage(&temparrow.arrowimg, L"arrow.png");
			playerArrows.push_back(temparrow);
		}
	}
}
void player::arrrowDraw() {
	for (auto s1 = playerArrows.begin(); s1 != playerArrows.end(); s1++) {
		putimage(s1->x, s1->y, &s1->arrowimg);
	}
}
void player::arrowMove() {
	for (auto s1 = playerArrows.begin(); s1 != playerArrows.end(); ) {
		if (s1->y < 0) {
			s1 = playerArrows.erase(s1);
		}
		else {
			s1->y -= s1->speed;
			s1++;
		}
	}
}
void player::arrowClear() {
	for (auto s1 = playerArrows.begin(); s1 != playerArrows.end();) {
		if (s1->x < -s1->arrowimg.getwidth() || s1->x>1080 || s1->y < 10) {
			s1 = playerArrows.erase(s1);
		}
		else {
			s1++;
		}
	}
}
bool player::judgeWin() {
	return score >= 100;
}
void player::scoreAdd(player& p) {
	for (auto s2 = enemy::enemies.begin(); s2 != enemy::enemies.end(); ) {
		if (s2->HP <= 0) {
			s2 = enemy::enemies.erase(s2);
			p.score += 10;
		}
		else {
			s2++;
		}
	}
}
void player::HPChange(player &p) {
	int enemySBe = enemy::enemies.size();
	enemy::enemyClear(p);
	int enemySAf = enemy::enemies.size();
	enemySCh(enemySAf, enemySBe);
	if (enemySCh(enemySAf, enemySBe) > 0) {
		p.HP -= 10 * (enemySCh(enemySAf, enemySBe));
	}
}